package com.ali.controller;

import com.ali.service.impl.TestServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {
    @Resource
    private TestServiceImpl testServiceImpl;

    @GetMapping("/hello")
    public String hello() {
        return testServiceImpl.hello();
    }

    @GetMapping("/error")
    public void error() {
        testServiceImpl.error();
    }

    @GetMapping("/add/attributes1")
    public Object addAttributes1(ModelMap modelMap) {
        log.info("modelMap：" + modelMap);
        return modelMap.getAttribute("addParam1");
    }

    @GetMapping("/add/attributes2")
    public Object addAttributes2(Model model) {
        log.info("model：" + model);
        Map<String, Object> modelMap = model.asMap();
        return modelMap.get("addParam1");
    }

    @GetMapping("/add/attributes3")
    public Object addAttributes3(@ModelAttribute("addParam1") String addParam) {
        log.info("addParam1：" + addParam);
        return addParam;
    }
}
